// const common = require("../../js/bus/info.js");
// components/ecInput.js
const componentBehavior = require('../../js/common/ComponentBehavior')

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    icon: {
      type: String,
      value: 'icon-phone'
    },
    name: {
      type: String,
      value: 'UserName'
    },
    placeholder: {
      type: String,
      value: '请输入账号'
    },
    hasyzm: {
      type: String,
      value: ''
    },
    hasimgyzm: {
      type: String,
      value: ''
    },
    hasPsdIcon:{
      type: Boolean,
      value: false
    },
    msg: {
      type: String,
      value: '获取验证码'
    },
    isPsd: {
      type: String,
      value: 'text'
    },
    maxLength: {
      type: Number,
      value: 11
    },
    value: {
      type: String,
      value: ''
    },
    disabled:{
      type:Boolean,
      value:false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    codeBase64: "",
    notifyTime: 60,
    isSendSmsCode: false, //是否已发送短信校验码
    msg: "获取验证码",
    callback: null,
    eyeOpen:false
  },
  behaviors: [componentBehavior],
  /**
   * 组件的方法列表
   */
  methods: {
    catchTapEvent:function(e){
      //console.log("catchTapEvent",e)
    },
    /*绑定输入事件 */
    bindInputEvent: function(e) {
      this.triggerEvent("bindinput", e)
    },
    /*绑定离开事件 */
    bindBlurEvent: function(e) {
      //console.log("bindblur")
      this.triggerEvent("bindblur", e)
    },
    bindFocusEvent:function(e){
      //console.log("bindFocusEvent")
    },
    /*绑定图片校验事件 */
    bindPicVerifyCode: function(e) {
      var that = this;
      if (typeof(this.data.callback) == "function")
        this.data.callback(function(content) {
          that.setData({
            codeBase64: 'data:image/png;base64,' + content.codeBase64,
          });
        });
    },
    /*绑定短信校验事件 */
    bindSmsVerifyCode: function(e) {
      var that = this;
      if (that.data.isSendSmsCode) return;
      if (typeof(this.data.callback) == "function")
        setTimeout(()=>{
          this.data.callback(function(content) {
            that.setData({
              isSendSmsCode: true,
              notifyTime: 60,
              msg: "60S"
            });
            that.decTime();
          });
        },500)
    },
    /*倒计时*/
    decTime: function() {
      var that = this;
      var notifyTime = that.data.notifyTime - 1;
      that.setData({
        notifyTime: notifyTime,
        msg: notifyTime + "s后重新获取"
      });
      if (notifyTime > 0) {
        setTimeout(function() {
          that.decTime();
        }, 1000)
      } else {
        that.setData({
          isSendSmsCode: false,
          msg: "获取验证码"
        });
      }

    },
    //密码可见
    bindEyeClick:function(){
      this.setData({
        eyeOpen: !this.data.eyeOpen
      })
    }
  }
})